package com.woniuxy.movie.system.controller;


import com.woniuxy.movie.commons.core.model.Result;
import com.woniuxy.movie.commons.core.util.JwtUtil;
import com.woniuxy.movie.system.dto.AccountDto;
import com.woniuxy.movie.system.form.AccountLoginForm;
import com.woniuxy.movie.system.service.SystemAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XIAO
 * @since 2023年10月10日
 */
@RestController
@RequestMapping("/systemAccount")
@Api(tags = "账号接口")
public class SystemAccountController {
    @Autowired
    SystemAccountService systemAccountService;

    @PostMapping("/login.api")
    @ApiOperation("登录")
    public Result<AccountDto> login(@RequestBody AccountLoginForm form, HttpServletResponse response){
        AccountDto accountDto = systemAccountService.login(form);
        HashMap<String, Object> map = new HashMap<>();
        map.put("accountId", accountDto.getAccountId());
        String authen_token = JwtUtil.createAdminToken(map, 30);
        response.setHeader("authen_token",authen_token);

        return Result.getResult(AccountDto.class).setData(accountDto).setMsg("登录成功");
    }

}

